﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
namespace GSLMS.Entity
{
    /// <summary>
    /// 特批申请信息表
    /// </summary>
    [DataContract(IsReference = true)]
    public partial class TB_APP_SPECIALINFO : IObjectWithChangeTracker, INotifyPropertyChanged
    {
        public TB_APP_SPECIALINFO()
        { }
        #region Model
        private long _id;
        private long _reginfoid;
        private string _custname;
        private long _salesmanid;
        private string _salesman;
        private long _depid;
        private string _depname;
        private long _productid;
        private string _productname;
        private string _specialtitle;
        private string _specialtype;
        private string _detail;
        private int _status;
        private string _createby;
        private Nullable<DateTime> _createdate;
        private int _sparefield1;
        private string _sparefield2;
        private string _sparefield3;

        /// <summary>
        /// 主键ID主键ID，唯一
        /// </summary>
        [DataMember]
        public long ID
        {
            get { return _id; }
            set
            {
                if (_id != value)
                {
                    if (ChangeTracker.ChangeTrackingEnabled && ChangeTracker.State != ObjectState.Added)
                    {
                        throw new InvalidOperationException("属性“ID”是对象键的一部分，不可更改。仅当未跟踪对象或对象处于“已添加”状态时，才能对键属性进行更改。");
                    }
                    _id = value;
                    OnPropertyChanged("ID");
                }
            }
        }
        /// <summary>
        /// 申请登记记录IDTB_App_RegInfo.ID
        /// </summary>
        [DataMember]
        public long REGINFOID
        {
            get { return _reginfoid; }
            set
            {
                if (_reginfoid != value)
                {
                    _reginfoid = value;
                    OnPropertyChanged("REGINFOID");
                }
            }
        }
        /// <summary>
        /// 客户名称 
        /// </summary>
        [DataMember]
        public string CUSTNAME
        {
            get { return _custname; }
            set
            {
                if (_custname != value)
                {
                    _custname = value;
                    OnPropertyChanged("CUSTNAME");
                }
            }
        }
        /// <summary>
        /// 项目经理记录ID
        /// </summary>
        [DataMember]
        public long SALESMANID
        {
            get { return _salesmanid; }
            set
            {
                if (_salesmanid != value)
                {
                    _salesmanid = value;
                    OnPropertyChanged("SALESMANID");
                }
            }
        }
        /// <summary>
        /// 项目经理
        /// </summary>
        [DataMember]
        public string SALESMAN
        {
            get { return _salesman; }
            set
            {
                if (_salesman != value)
                {
                    _salesman = value;
                    OnPropertyChanged("SALESMAN");
                }
            }
        }
        /// <summary>
        /// 所属部门记录ID
        /// </summary>
        [DataMember]
        public long DEPID
        {
            get { return _depid; }
            set
            {
                if (_depid != value)
                {
                    _depid = value;
                    OnPropertyChanged("DEPID");
                }
            }
        }
        /// <summary>
        /// 所属部门
        /// </summary>
        [DataMember]
        public string DEPNAME
        {
            get { return _depname; }
            set
            {
                if (_depname != value)
                {
                    _depname = value;
                    OnPropertyChanged("DEPNAME");
                }
            }
        }
        /// <summary>
        /// 贷款产品记录ID
        /// </summary>
        [DataMember]
        public long PRODUCTID
        {
            get { return _productid; }
            set
            {
                if (_productid != value)
                {
                    _productid = value;
                    OnPropertyChanged("PRODUCTID");
                }
            }
        }
        /// <summary>
        /// 贷款产品名称
        /// </summary>
        [DataMember]
        public string PRODUCTNAME
        {
            get { return _productname; }
            set
            {
                if (_productname != value)
                {
                    _productname = value;
                    OnPropertyChanged("PRODUCTNAME");
                }
            }
        }
        /// <summary>
        /// 标题
        /// </summary>
        [DataMember]
        public string SPECIALTITLE
        {
            get { return _specialtitle; }
            set
            {
                if (_specialtitle != value)
                {
                    _specialtitle = value;
                    OnPropertyChanged("SPECIALTITLE");
                }
            }
        }
        /// <summary>
        /// 类型包括：代收费用、其他
        /// </summary>
        [DataMember]
        public string SPECIALTYPE
        {
            get { return _specialtype; }
            set
            {
                if (_specialtype != value)
                {
                    _specialtype = value;
                    OnPropertyChanged("SPECIALTYPE");
                }
            }
        }
        /// <summary>
        /// 详细内容
        /// </summary>
        [DataMember]
        public string DETAIL
        {
            get { return _detail; }
            set
            {
                if (_detail != value)
                {
                    _detail = value;
                    OnPropertyChanged("DETAIL");
                }
            }
        }
        /// <summary>
        /// 审批状态0未提交，1审批中，2审批同意，3审批拒绝
        /// </summary>
        [DataMember]
        public int STATUS
        {
            get { return _status; }
            set
            {
                if (_status != value)
                {
                    _status = value;
                    OnPropertyChanged("STATUS");
                }
            }
        }
        /// <summary>
        /// 建档人
        /// </summary>
        [DataMember]
        public string CREATEBY
        {
            get { return _createby; }
            set
            {
                if (_createby != value)
                {
                    _createby = value;
                    OnPropertyChanged("CREATEBY");
                }
            }
        }
        /// <summary>
        /// 建档时间
        /// </summary>
        [DataMember]
        public Nullable<DateTime> CREATEDATE
        {
            get { return _createdate; }
            set
            {
                if (_createdate != value)
                {
                    _createdate = value;
                    OnPropertyChanged("CREATEDATE");
                }
            }
        }
        /// <summary>
        /// 预留字段1
        /// </summary>
        [DataMember]
        public int SPAREFIELD1
        {
            get { return _sparefield1; }
            set
            {
                if (_sparefield1 != value)
                {
                    _sparefield1 = value;
                    OnPropertyChanged("SPAREFIELD1");
                }
            }
        }
        /// <summary>
        /// 预留字段2
        /// </summary>
        [DataMember]
        public string SPAREFIELD2
        {
            get { return _sparefield2; }
            set
            {
                if (_sparefield2 != value)
                {
                    _sparefield2 = value;
                    OnPropertyChanged("SPAREFIELD2");
                }
            }
        }
        /// <summary>
        /// 预留字段3
        /// </summary>
        [DataMember]
        public string SPAREFIELD3
        {
            get { return _sparefield3; }
            set
            {
                if (_sparefield3 != value)
                {
                    _sparefield3 = value;
                    OnPropertyChanged("SPAREFIELD3");
                }
            }
        }




        #endregion Model

        #region ChangeTracking

        protected virtual void OnPropertyChanged(String propertyName)
        {
            if (ChangeTracker.State != ObjectState.Added && ChangeTracker.State != ObjectState.Deleted)
            {
                ChangeTracker.State = ObjectState.Modified;
            }
            if (_propertyChanged != null)
            {
                _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        protected virtual void OnNavigationPropertyChanged(String propertyName)
        {
            if (_propertyChanged != null)
            {
                _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { add { _propertyChanged += value; } remove { _propertyChanged -= value; } }
        private event PropertyChangedEventHandler _propertyChanged;
        private ObjectChangeTracker _changeTracker;

        [DataMember]
        public ObjectChangeTracker ChangeTracker
        {
            get
            {
                if (_changeTracker == null)
                {
                    _changeTracker = new ObjectChangeTracker();
                    _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
                }
                return _changeTracker;
            }
            set
            {
                if (_changeTracker != null)
                {
                    _changeTracker.ObjectStateChanging -= HandleObjectStateChanging;
                }
                _changeTracker = value;
                if (_changeTracker != null)
                {
                    _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
                }
            }
        }

        private void HandleObjectStateChanging(object sender, ObjectStateChangingEventArgs e)
        {
            if (e.NewState == ObjectState.Deleted)
            {
                ClearNavigationProperties();
            }
        }

        protected bool IsDeserializing { get; private set; }

        [OnDeserializing]
        public void OnDeserializingMethod(StreamingContext context)
        {
            IsDeserializing = true;
        }

        [OnDeserialized]
        public void OnDeserializedMethod(StreamingContext context)
        {
            IsDeserializing = false;
            ChangeTracker.ChangeTrackingEnabled = true;
        }

        protected virtual void ClearNavigationProperties()
        {
        }

        #endregion

    }
}

